﻿@model FCZLM.Core.Models.ProductUrls
@using FCZLM.Core.Models
@{
    Layout = null;
    var list = ViewBag._productsRepository as List<Products>;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Edit</title>
    <link href="/layui/css/layui.css" rel="stylesheet" />

</head>

<body>

    <div>

        <div class="layui-card">

            <div class="layui-card-header">修改图片</div>

            <div class="layui-card-body">

                <form class="layui-form">
                    <input type="hidden" name="Id" value="@Model.Id" />
                    <div class="layui-form-item">
                        <label class="layui-form-label">图片</label>
                        <div class="layui-input-block">
                            <input type="file" name="PicUrl1" id="uploadimg" />
                            <input type="hidden" name="PicUrl" id="url" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-block">
                            <img id="my_img" value="@Model.PicUrl" style="width:200px;height:200px" />
                        </div>
                    </div>
                    <div class="layui-form-item">

                        <label class="layui-form-label">图片类型</label>

                        <div class="layui-input-block">

                            <input type="text" value="@Model.PicType" name="PicType" required lay-verify="required" placeholder="请输入类型" autocomplete="off" class="layui-input">

                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">商品</label>
                        <div class="layui-input-block">
                            <select name="ProductId" lay-verify="required">
                                <option value=""></option>
                                @foreach (var item in list)
                                {
                                    if (Model.ProductId == item.Id)
                                    {
                                        <option value="@item.Id" selected>@item.Name</option>
                                    }
                                    else
                                    {
                                        <option value="@item.Id">@item.Name</option>
                                    }
                                }
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">

                        <div class="layui-input-block">

                            <button class="layui-btn" lay-submit lay-filter="editForm" data-type="text" id="fileNotifySubmit">修改</button><!--使用Ajax把formDemo改为editForm-->

                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>

                        </div>

                    </div>

                </form>

            </div>

        </div>

    </div>
    <script src="/layui/layui.js"></script>
    <script>
      
        //引入layui组件
        //layui.use("form", function () { });//使用Ajax方式需要把这行删除
        //使用Ajax方式
        layui.use(["form", 'layer', 'layedit', 'upload'], function () {

            var form = layui.form;

            var $ = layui.$;//引入layui组件
            var layedit = layui.layedit;
           
            var upload = layui.upload;
            //处理图片上传
            upload.render({
                elem: "#uploadimg",//点击谁上传图片
                url: "/FProductUrls/uploadimg",//图片上传到哪里
                done: function (res) {
                    //上传成功之后的处理
                    if (res.code == 0) {
                        //显示图片
                        $("#my_img").attr("src", res.path);
                        //path存起来
                        $("#url").val(res.path);
                    }
                }
            })
            //监听提交

            form.on('submit(editForm)', function (data) {

                $.post("/fproducturls/edits", data.field, function (res) {

                    if (res.isSuccess) {

                        layer.msg(res.msg, function () {

                            parent.window.location.href = "/fproducturls/index"//parent加上它是父页面做跳转

                        });

                    } else {

                        layer.msg(res.msg)

                    }

                });

                return false;

            });

        });

    </script>

</body>

</html>

